<template>
    <div>
        <el-form ref="agelRef" :model="form" label-width="156px" style="padding:0 40px 0px 20px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="任务名称" prop="taskName" label-width="70px">
                            {{form.taskName}}
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="12">
                        <el-form-item label="最新维护人" prop="maintainer">
                            {{task.maintainer}}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="最新维护时间" prop="maintainTime">
                            {{task.maintainTime}}
                        </el-form-item>
                    </el-col> -->
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="行政区划分析级别" prop="isCity" @change="changeCity">
                            <el-radio-group v-model="isCity">
                                <el-radio label="0">按区县</el-radio>
                                <el-radio label="1">按地市</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                </el-row>
                <template v-if="isCity=='0'">
                    <el-tabs v-model="activeName" type="card" class="demo-tabs" @tab-click="handleClick">
                        <el-tab-pane v-for="(item,index) in form.areaList" :key="index" :label="item.province==item.city?item.province + item.area:item.province + item.city + item.area" :name="index">
                            <el-form-item label="建筑物" :prop="`areaList.` + index + '.building'" :rules="rules.building">
                                <el-input v-model="item.building" placeholder="请输入建筑物" type="textarea" :rows="5" maxlength="2000" show-word-limit :disabled="isDisabled"/>
                            </el-form-item>
                            <el-form-item label="地震灾害重点隐患" :prop="`areaList.` + index + '.disasterHiddenDanger'" :rules="rules.disasterHiddenDanger">
                                <el-input v-model="item.disasterHiddenDanger" placeholder="请输入地震灾害重点隐患" type="textarea" :rows="5" maxlength="2000" show-word-limit :disabled="isDisabled"/>
                            </el-form-item>
                            <el-form-item label="生命线系统" :prop="`areaList.` + index + '.lifelineSystem'" :rules="rules.lifelineSystem">
                                <el-input v-model="item.lifelineSystem" placeholder="请输入生命线系统" type="textarea" :rows="5" maxlength="2000" show-word-limit :disabled="isDisabled"/>
                            </el-form-item>
                            <el-form-item label="重大基础设施" :prop="`areaList.` + index + '.majorInfrastructure'" :rules="rules.majorInfrastructure">
                                <el-input v-model="item.majorInfrastructure" placeholder="请输入重大基础设施" type="textarea" :rows="5" maxlength="2000" show-word-limit :disabled="isDisabled"/>
                            </el-form-item>
                            <el-form-item label="其他年度风险应对策略">
                                <el-input v-model="item.otherAnnualDisaster" placeholder="请输入其他年度风险应对策略" type="textarea" :rows="5" maxlength="2000" show-word-limit :disabled="isDisabled"/>
                            </el-form-item>
                        </el-tab-pane>
                    </el-tabs>  
                </template>            
                <template v-else>
                    <el-tabs v-model="activeName" type="card" class="demo-tabs" @tab-click="handleClick">
                        <el-tab-pane v-for="(item,index) in form.areaList" :key="index" :label="item.province==item.city?item.city:item.province+item.city" :name="index">
                            <el-form-item label="建筑物" :prop="`areaList.` + index +  '.building'" :rules="rules.building">
                                <el-input v-model="item.building" placeholder="请输入建筑物" type="textarea" :rows="5" maxlength="2000" show-word-limit :disabled="isDisabled"/>
                            </el-form-item>
                            <el-form-item label="地震灾害重点隐患" :prop="`areaList.` + index +  '.disasterHiddenDanger'" :rules="rules.disasterHiddenDanger">
                                <el-input v-model="item.disasterHiddenDanger" placeholder="请输入地震灾害重点隐患" type="textarea" :rows="5" maxlength="2000" show-word-limit :disabled="isDisabled"/>
                            </el-form-item>
                            <el-form-item label="生命线系统" :prop="`areaList.` + index +  '.lifelineSystem'" :rules="rules.lifelineSystem">
                                <el-input v-model="item.lifelineSystem" placeholder="请输入生命线系统" type="textarea" :rows="5" maxlength="2000" show-word-limit :disabled="isDisabled"/>
                            </el-form-item>
                            <el-form-item label="重大基础设施" :prop="`areaList.` + index +  '.majorInfrastructure'" :rules="rules.majorInfrastructure">
                                <el-input v-model="item.majorInfrastructure" placeholder="请输入重大基础设施" type="textarea" :rows="5" maxlength="2000" show-word-limit :disabled="isDisabled"/>
                            </el-form-item>
                            <el-form-item label="其他年度风险应对策略" :prop="`areaList.` + index +  '.otherAnnualDisaster'" :rules="rules.otherAnnualDisaster">
                                <el-input v-model="item.otherAnnualDisaster" placeholder="请输入其他年度风险应对策略" type="textarea" :rows="5" maxlength="2000" show-word-limit :disabled="isDisabled"/>
                            </el-form-item>
                        </el-tab-pane>
                    </el-tabs>  
                </template>
        </el-form>
    </div>
</template>

<script setup>
import { getArea } from "@/api/suggestions/analyse.js";
import { BLOCK_SCOPED_SYMBOL } from "@babel/types";
const { proxy } = getCurrentInstance();
const emit = defineEmits();
const props = defineProps({
  form: {
    type: Object,
  },
  task: {
    type: Object
  },
  isDisabled:{
    type:Boolean,
  }
});
const activeName = ref('0')
const data = reactive({
    rules: {
        building: [{ required: true, message: "请输入建筑物", trigger: 'blur', }],
        disasterHiddenDanger: [{ required: true, message: "请输入地震灾害重点隐患", trigger: 'blur' }],
        lifelineSystem: [{ required: true, message: '请输入生命线系统', trigger: 'blur'}],
        majorInfrastructure: [{ required: true, message: '请输入重大基础设施', trigger: 'blur'}],
    }
})
const { rules } = toRefs(data)
const { form, task ,isDisabled} = toRefs(props)
const isCity = ref('0');

// 初始下标
function initActiveName(){
    activeName.value = '0';
}


function changeCity(){
    activeName.value = '0';
    getAreaData({flag:isCity.value,taskDistrict:form.value.taskDistrict,suggestionName:'年度风险应对策略建议',taskNum:form.value.taskNum})
}

// 获取 区县或者地市
function getAreaData(isCity) {
    getArea(isCity).then(response => {
        emit("changeAreaList1", response.data['年度风险应对策略建议']);
    })
}

function getAreaList1(){
    emit("getAreaList1", form.value.areaList);
}

function handleClick(tab, event){
    // console.log(activeName.value,'======');
}
function getAgelRef(){
    return proxy.$refs['agelRef']
}
defineExpose({
    getAreaList1,
    initActiveName,
    getAgelRef
})
</script>